package im.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class TestClient implements Runnable{
	
	private OutputStream os;
	private InputStream is;
	
	public static void main(String[] args) throws UnknownHostException, IOException {
		TestClient client = new TestClient();
		client.run();
	}
	@Override
	public void run() {
		Socket socket;
		try {
			socket = new Socket("127.0.0.1",2333);
		
		while(true){
		final InputStream is = socket.getInputStream();
		OutputStream os = socket.getOutputStream();
		
		Scanner scanner = new Scanner(System.in);
		System.out.println("please input:");
		String msgToServer = scanner.nextLine();
		os.write((msgToServer+"\n").getBytes());
		System.out.println("your input>"+msgToServer);
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				BufferedReader br = new BufferedReader(new InputStreamReader(is));
				while(br!=null){
				try {
					System.out.println("server say"+br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
				}
				
			}
		}).start();;
		}
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
	}
}
